package com.sky.innerClass;

import sky.JULLog.MyLogger;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.logging.Logger;

public class Client {


    private  static Logger log  = MyLogger.getLogger(Client.class);

    /**
     * 使用 方法内部类  创建一个 HttpServlet
     * 当然你这样创建  这个 {@link HttpServlet HttpServlet } 当然是残次品,  没啥卵用 , 仅仅是作为演示而已;
     * */
    private static HttpServlet createAServlet(  ){

        return  new HttpServlet() {
            private static final long serialVersionUID = 1L;

            @Override
            protected void service(HttpServletRequest request, HttpServletResponse response) throws  IOException {
                response.setCharacterEncoding("UTF-8");
                response.setContentType("text/plain");
                response.setHeader("Server", "Embedded Tomcat");
                try (Writer writer = response.getWriter()) {
                    writer.write("Hello, Embedded Tomcat!");
                    writer.flush();
                }
            }

            @Override
            protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                log.info("globalServlet........");
                super.doGet(req, resp);
            }


            @Override
            protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                log.info("globalServlet........");

                super.doPost(req, resp);
            }
        };


    }


    public static void main(String[] args) {

        HttpServlet httpServlet = new Client().createAServlet();
        System.out.println("httpServlet.getServletConfig() ==>  " + httpServlet.getServletConfig());

    }


}
